//
// Created by zhupi on 2024/11/13.
//

#ifndef DEMO2_IMPORT_PROJECT_H
#define DEMO2_IMPORT_PROJECT_H

#include <QDialog>
#include <QFileDialog>
#include <QMessageBox>
#include <QPushButton>
#include <QVBoxLayout>
#include <QWidget>
#include <QLineEdit>

class ImportProject : public QDialog
{
    Q_OBJECT

public:
    ImportProject(QWidget *parent = nullptr) : QDialog(parent) {
            setWindowTitle("导入.aedt文件");

            QVBoxLayout *layout = new QVBoxLayout(this);

            pathLineEdit = new QLineEdit(this);
            pathLineEdit->setPlaceholderText("选择.aedt文件路径...");
            pathLineEdit->setReadOnly(true);  // 设置为只读
            layout->addWidget(pathLineEdit);

            QPushButton *browseButton = new QPushButton("浏览", this);
            connect(browseButton, &QPushButton::clicked, this, &ImportProject::browseFile);
            layout->addWidget(browseButton);

            QPushButton *importButton = new QPushButton("导入", this);
            connect(importButton, &QPushButton::clicked, this, &ImportProject::importFile);
            layout->addWidget(importButton);

            setLayout(layout);
    }

private slots:
    void browseFile() {
        QString filePath = QFileDialog::getOpenFileName(this, "选择.aedt文件", "", "AEDT Files (*.aedt)");
        if (!filePath.isEmpty()) {
            pathLineEdit->setText(filePath);
        }
    }

    void importFile() {
        QString filePath = pathLineEdit->text();
        if (filePath.isEmpty()) {
            QMessageBox::warning(this, "警告", "请先选择.aedt文件路径！");
        } else {
            // 在这里添加导入文件的逻辑
            QMessageBox::information(this, "导入成功", "成功导入: " + filePath);
        }
    }

private:
    QLineEdit *pathLineEdit;
};


#endif //DEMO2_IMPORT_PROJECT_H
